#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  getline(cin, s);
  char a;  // 操作符号
  cin >> a;
  if (a == 'D') {  // 删符
    char b;        // 待删除的字符
    cin >> b;
    int found = s.find(b, 0);  // 从0位置找字符b
    if (found != string::npos) s.erase(found, 1);
  } else if (a == 'I') {  // 插入符
    string a, b;          // 待插入的字符
    cin >> a >> b;
    int found = s.rfind(a);  // 从最后找字符b
    if (found != string::npos) s.insert(found, b);
  } else if (a == 'R') {  // 替换符
    string s1;            // 被替换的字符/字符串
    string s2;            // 替换的字符/字符串
    cin >> s1 >> s2;
    int p = 0;
    while (true) {
      int found = s.find(s1, p);
      if (found == string::npos) break;  // 如果找不到就退出
      s.replace(found, 1, s2);           // 找到就替换
      p = found + 1;
    }
  }
  cout << s;
  return 0;
}